<?php
/**
 * [Fengxu!] (C)2008-2009 SSBT Inc.
 * This is NOT a freeware, use is subject to license terms
 * $Id: btcstatus.inc.php Tue Apr 08 01:56:39 GMT 2008 $
 * @author fengxu qq:250484464 <zhiming0824@163.com>
 * @version $Id 01:56:39$
 * @license fengxu
 */
require_once 'common.inc.php';
!in_array('2',$larr)&&adminmsg('你没有被赋予操作该项的权限！');
if($action=='btcwarn')
{
	$numq = $db->query("SELECT * FROM msys_btc");
	$nums = $db->num_rows($numq);
	$ppp = ceil($nums/20);
	if(!$page||!is_numeric($page) || $page>$nums) $page=1;
	$page = intval($page);
	$start_limit = ($page-1)*20;
	$sql = "SELECT btcip,port,btcname FROM  msys_btc LIMIT $start_limit,20";
	$query = $db->query($sql);
	$btcdb = $btclist = array();
	while ($btclist=$db->fetch_array($query))
	{
		if($btclist['btcip']&&$btclist['port'])
		{
			$sql = "SELECT freespace,btcspacewarn FROM area WHERE `describe`='$btclist[btcip]' AND port='$btclist[port]'";
			$queryw = $dsdb->query($sql);
			$rs = $dsdb->fetch_array($queryw);
			$freespace = $rs['btcspacewarn'];
			$btclist['freespace'] = $rs['freespace']?$rs['freespace'].'G' :'';
			if($btclist['freespace'])
			{
				$rs['freespace']>$freespace ? $btclist['img'] = "<img src=\"images/lan.jpg\" alt=\"正常状态\" >" : $btclist['img'] = "<img src=\"images/hong.jpg\" alt=\"空间不足\" >" ;
			}	
				$btclist['btcspacewarn'] = $rs['btcspacewarn'] ? $rs['btcspacewarn'].'G' :'';
			if($btclist['btcip'])
			{
				$cactisql = "SELECT g.id FROM  graph_tree_items g LEFT JOIN host h ON g.host_id=h.id WHERE h.hostname='$btclist[btcip]'";
				$cactiquery = $cacti->query($cactisql);
				$leaf_id = $cacti->result($cactiquery,0);
				if($leaf_id)
				{
					$btclist['leaf_id'] = $leaf_id;
				}	
			}					
		}
		$btclist['url'] = 'btcstatus.inc.php?action=modify&params='.urlencode($btclist['btcip'].':'.$btclist['port'])."&mtype=warn&freespace=$freespace";
		$btcdb[] = $btclist;
	}
	$pages = numofpage($nums,$page,$ppp,'btcstatus.inc.php?action=btcwarn&');
include systemplate('btcstatus_warn');
}
elseif ($action=='btcdelete')
{
	$numq = $db->query("SELECT * FROM msys_btc");
	$nums = $db->num_rows($numq);
	$ppp = ceil($nums/20);
	if(!$page||!is_numeric($page) || $page>$nums) $page=1;
	$page = intval($page);
	$start_limit = ($page-1)*20;
	$sql = "SELECT btcip,port,btcname FROM  msys_btc LIMIT $start_limit,20";	
	$query = $db->query($sql);
	$btcdb = $btclist = array();
	while ($btclist=$db->fetch_array($query))
	{
		$sql = "SELECT freespace,btcspacedelete FROM area WHERE `describe`='$btclist[btcip]' AND port='$btclist[port]'";
		$queryd = $dsdb->query($sql);
		$rs = $dsdb->fetch_array($queryd);
		$freespace = $rs['btcspacedelete'];
		$btclist['freespace'] = $rs['freespace'] ? $rs['freespace'].'G' : '';
		if($btclist['freespace'])
		{
			$rs['freespace']>$freespace ? $btclist['img'] = "<img src=\"images/lan.jpg\" alt=\"正常状态\" >" : $btclist['img'] = "<img src=\"images/hong.jpg\" alt=\"空间不足\" >" ;
		}
		if($btclist['btcip'])
		{
			$cactisql = "SELECT g.id FROM  graph_tree_items g LEFT JOIN host h ON g.host_id=h.id WHERE h.hostname='$btclist[btcip]'";
			$cactiquery = $cacti->query($cactisql);
			$leaf_id = $cacti->result($cactiquery,0);
			if($leaf_id)
			{
				$btclist['leaf_id'] = $leaf_id;
			}	
		}		
		$btclist['btcspacedelete'] = $rs['btcspacedelete'] ? $rs['btcspacedelete'].'G':'';	
		$btclist['url'] = 'btcstatus.inc.php?action=modify&params='.urlencode($btclist['btcip'].':'.$btclist['port'])."&mtype=del&freespace=$freespace";
		$btcdb[] = $btclist;	
	}
	$pages = numofpage($nums,$page,$ppp,'btcstatus.inc.php?action=btcdelete&');
	include systemplate('btcstatus_del');
}
elseif ($action=='modify')
{
	$btcip = $btcport = '';
	$params = trim($params);
	$parr = explode(':',$params);
	$btcip = $parr[0];
	$btcport = $parr[1];
	if(!$modifysubmit)
	{

		if($mtype=='del')

		{

			$tsinfo = '设定BTC删除线值：';

		}

		elseif ($mtype=='warn')

		{

			$tsinfo = '设定BTC警告线值：';

		}

		include systemplate('btcstatus_mdy');

		exit();

	}

	$acceptsize = intval($acceptsize);

	if($mtype=='del')

	{

		$set = "btcspacedelete='$acceptsize'";

	}elseif ($mtype=='warn')

	{

		$set = "btcspacewarn='$acceptsize'";

	}

	$dsdb->query("UPDATE area SET $set WHERE `describe`='$btcip' AND port='$btcport'");

	adminmsg('修改成功！！',$mtype=='del'? 'btcstatus.inc.php?action=btcdelete' : 'btcstatus.inc.php?action=btcwarn');

}

?>